package cn.edu.scau.cmi.pengzhijie.client;

import cn.edu.scau.cmi.pengzhijie.sington.Chairman;
import cn.edu.scau.cmi.pengzhijie.sington.Marshal;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MultipleClient extends Application{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Button button = new Button("创建");
		button.setLayoutX(130);
		button.setLayoutY(400);
		Text text = new Text("开国元帅名称：");
		text.setLayoutX(50);
		text.setLayoutY(100);
		TextField textField = new TextField();
		textField.setMinWidth(80);
		textField.setLayoutX(140);
		textField.setLayoutY(85);
		Label textArea = new Label();
		textArea.setLayoutX(50);
		textArea.setLayoutY(110);
		Group group = new Group();
		group.getChildren().add(button);
		group.getChildren().add(text);
		group.getChildren().add(textArea);
		group.getChildren().add(textField);
		Scene scene = new Scene(group, 800, 800);
		primaryStage.setTitle("多例模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	button.setOnAction(new EventHandler<ActionEvent>() {
			String str = "";
			@Override
			public void handle(ActionEvent event) {
				// TODO Auto-generated method stub
				Marshal marshal = null;
				String nowName = textField.getText();
				marshal = marshal.getInstance(textField.getText());
				if(!nowName.equals(marshal.getName())) {
					// str = str + "创建开国元帅为" + marshal.getName() + ",不能创建" + nowName + "为开国元帅" + "\n";
					 str = str + "已经创立完十大开国元帅，不能再创立\n";
					 textArea.setText(str);
				} else {
					str = str + "创建开国元帅成功，当前十大元帅之一为：" + nowName + "," +marshal + "\n";
					textArea.setText(str);
				}
				
			}
		});
	}
}
